package com.na.proxy;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Log {

	private static Log instance;
	
	private String tag;
	private DateFormat df = new SimpleDateFormat("yyyy-MM-dd|HH:mm:ss");
	
	public Log(String tag) {
		this.tag = tag;
	}
	
	public Log(Class<?> cls) {
		this(cls.getSimpleName());
	}
	
	public static Log getDefault() {
		if (instance == null) {
			instance = new Log(Log.class);
		}
		return instance;
	}
	
	public void info(String info) {
		System.out.println(now() + " [" + tag + "]" + info);
	}
	
	public void error(Throwable t) {
		t.printStackTrace();
	}
	
	public void error(Throwable t, String error) {
		System.err.println(now() + " [" + tag + "]" + error);
		t.printStackTrace();
	}
	
	private String now() {
		return df.format(new Date());
	}
	
}
